<template>
<div>
  <div>
  <Button type="primary" @click="add"> 新增</Button>
</div>
  <Table border :columns="columns12" :data="data">
    <template slot-scope="{ row }" slot="name">
      <strong>{{ row.name }}</strong>
    </template>
    <template slot-scope="{ row, index }" slot="action">
      <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">编辑</Button>
      <Button type="error" size="small" @click="remove(row)">删除</Button>
    </template>
  </Table>
  <el-dialog :visible.sync="addClassify" v-if="addClassify" :close-on-click-modal="false">
    <addClassify @after="getClassify" @hideDialog="hideen"></addClassify>
  </el-dialog>
  <el-dialog :visible.sync="updateClassify" v-if="updateClassify" :close-on-click-modal="false">
    <UpdateClassify @after="getClassify" :data="Data" @niubi="hideen"></UpdateClassify>
  </el-dialog>
  </div>
</template>

<script>
import addClassify from "_c/Classify/addClassify";
import UpdateClassify from "_c/Classify/UpdateClassify";
export default {
  name: "BookType",
  components:{addClassify,UpdateClassify},
  data () {
    return {
      addClassify:false,
      updateClassify:false,
      columns12: [
        {
          title: '类型名称',
          slot: 'name'
        },
        {
          title: '备注',
          key: 'remarkers'
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      data: []
    }
  },
  methods: {
    show (row) {
        this.updateClassify=true
        this.Data=row
    },
    remove (row) {
     this.$confirm("确定删除吗","提示").then(()=>{
       this.http.post("/deleteClassify",this.qs.parse(row)).then(res=>{
         if (res.data){
           this.$Message.success('删除成功')
           this.getClassify();
         }else {
           this.$Message.error("删除失败")
         }
       })
     })
    },
    add(){
      this.addClassify=true
    },
    getClassify(){
      this.http.post("/getClassify").then(res => {
        if (res.data){
          this.data=res.data;
          console.log(res.data)
          this.$store.commit("setType",res.data)
        }
      })
    },
    hideen(){
      this.addClassify=false;
      this.updateClassify=false;
    }
  },
  created() {
    this.getClassify();
  }
}
</script>

<style scoped>

</style>
